package com.cash.loan.modular.cash.service.impl;

import com.cash.loan.common.entity.UserInfo;
import com.cash.loan.common.util.RedisUtil;
import com.cash.loan.modular.cash.dao.ProductVisitMapper;
import com.cash.loan.modular.cash.model.ProductVisit;
import com.cash.loan.modular.cash.service.StatisticsPvUvService;
import com.cash.loan.modular.user.dao.CashUserLoginMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @Date 2018-07-11 10:51
 */
@Service
public class StatisticsPvUvServiceImpl implements StatisticsPvUvService {

    @Autowired
    private CashUserLoginMapper userLoginMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private ProductVisitMapper visitMapper;

    /**
     * 统计服务实现
     * @param userInfo
     * @param productId
     */
    @Override
    public void statisticsPvUv(UserInfo userInfo,Long productId,Integer type) throws Exception {

        Long userId = null;

        if(null != userInfo.getUserId()) {
            userId = userInfo.getUserId();
        } else {
            return;
        }

        ProductVisit productVisit = new ProductVisit();

        productVisit.setProductId(productId);

        productVisit.setVisitorId(userId);

        productVisit.setType(type);

        visitMapper.insert(productVisit);

    }
}
